﻿using AiFrame.InterfaceLib.Plugins;


namespace AiFrame.InterfaceLib.Data.Patterns
{
    /// <summary>
    /// This Singleton class can be used for plugins to store the ICoreInterface reference 
    /// to access them from different classes.
    /// Furthermore, the initializing method takes and stores
    /// the program path to.
    /// Throught the singleton pattern plugins using this structure 
    /// have to derive from this class.
    /// </summary>
    public abstract class PluginSingleton<T> where T: new()
    {
        /// <summary>
        /// The current instance.
        /// </summary>
        public static readonly T Instance = new T();

        /// <summary>
        /// The coreinterface reference
        /// </summary>
        private ICoreInterface _coreInterface;

        /// <summary>
        /// The program/plugin path.
        /// </summary>
        private string _pluginPath;

        /// <summary>
        /// Initializes the class.
        /// </summary>
        /// <param name="coreInterface">The coreinterface reference.</param>
        /// <param name="pluginPath">The plugin/program path.</param>
        public void Initialize(ICoreInterface coreInterface, string pluginPath)
        {
            _coreInterface = coreInterface;
            _pluginPath = pluginPath;
            Initialize();
        }

        protected abstract void Initialize();

        /// <summary>
        /// Returns the coreinterface.
        /// </summary>
        public ICoreInterface CoreInterface
        {
            get
            {
                return _coreInterface;
            }
        }
    }
}